package com.chris.vue.models.items;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by Chris Chan
 * 2020/8/16 23:52
 * Use for:
 * Explain: 包含详细信息的菜单
 * 不需要前端预设路由数据，不需要做过滤，只需要写好页面，由后端数据动态构建
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class MenuInfoItem {
    private String name;
    private String path;
    private String redirect;
    private String url;
    private String id;
    private String title;
    private String icon;
    private Integer sort;
    private Integer hidden;
    private List<String> roles;
    private List<MenuInfoItem> children;

    public MenuInfoItem(String name, String path, String redirect, String url, String id, String title, String icon, Integer sort, Integer hidden, String... roles) {
        this.name = name;
        this.path = path;
        this.redirect = redirect;
        this.url = url;
        this.id = id;
        this.title = title;
        this.icon = icon;
        this.sort = sort;
        this.hidden = hidden;
        addRoles(roles);
    }

    private void addRoles(String... roles) {
        if (CollectionUtils.isEmpty(this.roles)) {
            this.roles = new ArrayList<>(16);
        }
        this.roles.addAll(Arrays.asList(roles));
    }

    public MenuInfoItem(String name, String path, String redirect, String url, String id, String title, String icon, Integer sort, Integer hidden) {
        this.name = name;
        this.path = path;
        this.redirect = redirect;
        this.url = url;
        this.id = id;
        this.title = title;
        this.icon = icon;
        this.sort = sort;
        this.hidden = hidden;
    }
}
